home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / drcpas10.zip / ABSDISK.ASM next >
Assembly Source File  |  1992-07-30  |  9KB  |  210 lines

  1.         IDEAL
  2.         MODEL TPASCAL
  3.  
  4.         DATASEG
  5.         EXTRN    dosver:WORD
  6.         EXTRN    abserror:WORD
  7.  
  8. STRUC   pack
  9.   sec   dd       ?
  10.   num   dw       ?
  11.   buf   dd       ?
  12. ENDS
  13.  
  14. packet  pack     ?
  15. dummy   db       20h dup (?)
  16.  
  17.         CODESEG
  18.  
  19. IF 0
  20. ----------25---------------------------------
  21. INT 25 - DOS 1+ - ABSOLUTE DISK READ (except partitions > 32M)
  22.         AL = drive number (00h = A:, 01h = B:, etc)
  23.         CX = number of sectors to read
  24.         DX = starting logical sector number (0000h - highest sector on drive)
  25.         DS:BX -> buffer for data
  26. Return: CF clear if successful
  27.         CF set on error
  28.             AH = status
  29.                  80h device failed to respond (timeout)
  30.                  40h seek operation failed
  31.                  20h controller failed
  32.                  10h data error (bad CRC)
  33.                  08h DMA failure
  34.                  04h requested sector not found
  35.                  03h write-protected disk (INT 26 only)
  36.                  02h bad address mark
  37.                  01h bad command
  38.             AL = error code (same as passed to INT 24 in DI)
  39.         may destroy all other registers except segment registers
  40. Notes:  original flags are left on stack, and must be popped by caller
  41.         this call bypasses the DOS filesystem
  42. BUG:    DOS 3.1 through 3.3 set the word at ES:[BP+1Eh] to FFFFh if AL is an
  43.         invalid drive number
  44. SeeAlso: INT 13/AH=02h,INT 26
  45. ----------25---------------------------------
  46. INT 25 - DOS 3.31+ - ABSOLUTE DISK READ (>32M hard-disk partition)
  47.         AL = drive number (0=A, 1=B, etc)
  48.         CX = FFFFh
  49.         DS:BX -> disk read packet (see below)
  50. Return: same as above
  51. Notes:  partition is potentially >32M (and requires this form of the call) if
  52.           bit 1 of device attribute word in device driver is set
  53.         original flags are left on stack, and must be removed by caller
  54.         this call bypasses the DOS filesystem
  55. SeeAlso: INT 13/AH=02h,INT 26
  56.  
  57. Format of disk read packet:
  58. Offset  Size    Description
  59.  00h    DWORD   sector number
  60.  04h    WORD    number of sectors to read
  61.  06h    DWORD   transfer address
  62. ENDIF
  63.  
  64. PROC    absread  FAR drive:BYTE, sector:DWORD, numsecs:WORD, buffer:FAR PTR
  65.         PUBLIC   absread
  66.         push     ds                ; save ds
  67.         mov      ax, [dosver]      ; get DOS version
  68.         cmp      al, 3             ; after version 3?
  69.         jg       @@extended        ; uses extended partitions
  70.         cmp      ah, 30            ; after 3.30?
  71.         jg       @@extended        ; uses extended partitions
  72. @@normal:
  73.         mov      cx, [numsecs]     ; number of sectors to read
  74.         les      ax, [sector]      ; sector number to read
  75.         or       ax, ax            ; high word should be zero
  76.         jz       @@okay            ;  on normal partitions
  77.         mov      ax, 0408h         ; else return with
  78.         jmp      short @@error     ;  sector not found error
  79. @@okay:
  80.         mov      dx, es            ; low word of sector number
  81.         lds      bx, [buffer]      ; ds:bx points to buffer
  82.         jmp      short @@both      ; skip past extended setup
  83. @@extended:
  84.         mov      bx, OFFSET packet ; ds:bx points to packet
  85.         mov      cx, 0FFFFh        ; -1 indicates extended partitions
  86.         les      ax, [sector]
  87.         mov      dx, es
  88.         mov      [WORD packet.sec], ax
  89.         mov      [(WORD packet.sec)+2], dx
  90.         les      ax, [buffer]
  91.         mov      dx, es
  92.         mov      [WORD packet.buf], ax
  93.         mov      [(WORD packet.buf)+2], dx
  94.         mov      ax, [numsecs]
  95.         mov      [packet.num], ax  ; set up data packet
  96. @@both:
  97.         mov      al, [drive]       ; drive number (0 = A:, 1 = B:, etc.)
  98.         push     ds                ; load es
  99.         pop      es                ; with ds
  100.         push     bp                ; save bp
  101.         mov      bp, OFFSET dummy  ; es:bp points to dummy
  102.         int      25h               ; absolute disk read
  103.         jc       short @@error     ; was there an error?
  104. @@noerror:
  105.         xor      ax, ax            ; zero the ax register
  106. @@error:
  107.         add      sp, 2             ; clear flags off stack
  108.         pop      bp                ; restore bp
  109.         pop      ds                ; restore ds
  110.         mov      [abserror], ax    ; error code in ax
  111.         ret                        ; and return
  112.         ENDP     absread
  113.  
  114. IF 0
  115. ----------26---------------------------------
  116. INT 26 - DOS 1+ - ABSOLUTE DISK WRITE (except partitions > 32M)
  117.         AL = drive number (00h = A:, 01h = B:, etc)
  118.         CX = number of sectors to write
  119.         DX = starting logical sector number (0000h - highest sector on drive)
  120.         DS:BX -> data to write
  121. Return: CF clear if successful
  122.         CF set on error
  123.             AH = status
  124.                  80h device failed to respond (timeout)
  125.                  40h seek operation failed
  126.                  20h controller failed
  127.                  10h data error (bad CRC)
  128.                  08h DMA failure
  129.                  04h requested sector not found
  130.                  03h write-protected disk (INT 26 only)
  131.                  02h bad address mark
  132.                  01h bad command
  133.             AL = error code (same as passed to INT 24 in DI)
  134.         may destroy all other registers except segment registers
  135. Notes:  original flags are left on stack, and must be popped by caller
  136.         this call bypasses the DOS filesystem
  137. BUG:    DOS 3.1 through 3.3 set the word at ES:[BP+1Eh] to FFFFh if AL is an
  138.         invalid drive number
  139. SeeAlso: INT 13/AH=03h,INT 25
  140. ----------26---------------------------------
  141. INT 26 - DOS 3.31+ - ABSOLUTE DISK WRITE (>32M hard-disk partition)
  142.         AL = drive number (0=A, 1=B, etc)
  143.         CX = FFFFh
  144.         DS:BX -> disk write packet (see below)
  145. Return: same as above
  146. Notes:  partition is potentially >32M (and requires this form of the call) if
  147.           bit 1 of device attribute word in device driver is set
  148.         original flags are left on stack, and must be removed by caller
  149.         this call bypasses the DOS filesystem
  150. SeeAlso: INT 13/AH=03h,INT 25
  151.  
  152. Format of disk write packet:
  153. Offset  Size    Description
  154.  00h    DWORD   sector number
  155.  04h    WORD    number of sectors to read
  156.  06h    DWORD   transfer address
  157. ENDIF
  158.  
  159. PROC    abswrite FAR drive:BYTE, sector:DWORD, numsecs:WORD, buffer:FAR PTR
  160.         PUBLIC abswrite
  161.         push     ds                ; save ds
  162.         mov      ax, [dosver]      ; get DOS version
  163.         cmp      al, 3             ; after version 3?
  164.         jg       @@extended        ; uses extended partitions
  165.         cmp      ah, 30            ; after 3.30?
  166.         jg       @@extended        ; uses extended partitions
  167. @@normal:
  168.         mov      cx, [numsecs]     ; number of sectors to read
  169.         les      ax, [sector]      ; sector number to read
  170.         or       ax, ax            ; high word should be zero
  171.         jz       @@okay            ;  on normal partitions
  172.         mov      ax, 0408h         ; else return with
  173.         jmp      short @@error     ;  sector not found error
  174. @@okay:
  175.         mov      dx, es            ; low word of sector number
  176.         lds      bx, [buffer]      ; ds:bx points to buffer
  177.         jmp      short @@both      ; skip past extended setup
  178. @@extended:
  179.         mov      bx, OFFSET packet ; ds:bx points to packet
  180.         mov      cx, 0FFFFh        ; -1 indicates extended partitions
  181.         les      ax, [sector]
  182.         mov      dx, es
  183.         mov      [WORD packet.sec], ax
  184.         mov      [(WORD packet.sec)+2], dx
  185.         les      ax, [buffer]
  186.         mov      dx, es
  187.         mov      [WORD packet.buf], ax
  188.         mov      [(WORD packet.buf)+2], dx
  189.         mov      ax, [numsecs]
  190.         mov      [packet.num], ax  ; set up data packet
  191. @@both:
  192.         mov      al, [drive]       ; drive number (0 = A:, 1 = B:, etc.)
  193.         push     ds                ; load es
  194.         pop      es                ; with ds
  195.         push     bp                ; save bp
  196.         mov      bp, OFFSET dummy  ; es:bp points to dummy
  197.         int      26h               ; absolute disk write
  198.         jc       short @@error     ; was there an error?
  199. @@noerror:
  200.         xor      ax, ax            ; zero the ax register
  201. @@error:
  202.         add      sp, 2             ; clear flags off stack
  203.         pop      bp                ; restore bp
  204.         pop      ds                ; restore ds
  205.         mov      [abserror], ax    ; error code in ax
  206.         ret                        ; and return
  207.         ENDP
  208.  
  209.         END
  210.